package ZZ_backup;

import java.io.*;
import java.sql.SQLException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

import LawsonTransformJava.pgm.PR560RecType1;
import LawsonTransformJava.pgm.PR560RecType2;
import LawsonTransformJava.pgm.PR560RecType3;


public class PR560Control_backup implements Runnable {

	private File output = null;
	private FileWriter outputWriter = null;
	private DateFormat df = null;
	private String whereClause = null;
	private boolean allowBlanks = false;
	private int payrollYear = 0;

	public PR560Control(File output, int payrollYear, boolean allowBlanks) {
		this.output = output;
		this.allowBlanks = allowBlanks;
		this.payrollYear = payrollYear;
	}
	
	public void run() {
		try {
		    df = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
//		    output = new File("c:/PR560.csv");
		    outputWriter = new FileWriter(output); 
			PR560RecType1 pr560Rec1 = new PR560RecType1(output, null, payrollYear, allowBlanks);
			PR560RecType2 pr560Rec2 = new PR560RecType2(output, allowBlanks);
			PR560RecType3 pr560Rec3 = new PR560RecType3(output, allowBlanks);
			if (whereClause!=null) {
				pr560Rec1.setWhereClause(whereClause);
				pr560Rec2.setWhereClause(whereClause);
				pr560Rec3.setWhereClause(whereClause);
			}
			pr560Rec1.run();
			pr560Rec2.run();
			pr560Rec3.run();
		} catch (IOException e) {
		// Could no write properties file
			System.out.println("IOException: " + e);
			System.exit(1);
		} catch (SQLException e) {
			// Could not connect to the database
			System.out.println("SQLException: " + e);
			System.exit(1);
		}
	}
	
	public void setWhereCLause(String where) {
		this.whereClause = where;
	}
}
